import os

import api
import scripts
from api.api_mp import ApiMp
from tools.asserts import Asserts
from tools.getloger import GetLogger
import pytest

logger = GetLogger().get_logger()
asserts = Asserts()

data = {
    "accounts": "hami",
    "pwd": "123456",
    "type": "username"
}


class TestMp:
    token = None


    def setup_class(self):
        self.mp = ApiMp()

    @pytest.mark.parametrize('accounts,pwd,type', [(data['accounts'], data['pwd'], data['type'])])
    def test_mp_login(self, accounts, pwd, type):
        data = {
            "accounts": "hami",
            "pwd": "123456",
            "type": "username"
        }
        login = self.mp.api_mp_login(accounts, pwd, type)
        logger.info("登录的结果为{}".format(login))

        print(login.json())
        msg = login.json().get('msg')
        login_token = login.json().get('data')['token']
        asserts.assert_login(msg)
        print(login_token)
        self.token = login_token
        api.header['token']=self.token
        print(api.header)
        return login_token

    def test_get_in(self):
        t=self.mp.api_mp_article(api.header.get("token"))
        print(t.text)
        # assert '登录成功' == (information.json()['msg'])


if __name__ == '__main__':
    pytest.main()
    os.system("allure generate ./report -o ./report --clean")
